const express=require('express')
const album=express.Router()
const axios=require('axios')

//专辑分页查询
album.get('/album/aueryByPage',(req,res)=>{
    let {pageSize,pageNow}=req.query
    axios({
        url:'/Admin/Album/queryByPage',
        params:{
            pageNow:pageNow||1,
            pageSize:pageSize||6
        },
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
    }).then(data=>{
        res.status(200).json({
            key:data.data
        })
    }).catch(err=>{
        res.status(500).json({
            err:err
        })
    })
})

//专辑删除
album.delete('/album/delete',(req,res)=>{
    let {id}=req.query
    axios({
        url:'/Admin/Album/delete',
        method:'delete',
        params:{
            id:id
        },
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
    }).then(data=>{
        res.status(200).json({
            key:data.data
        })
    }).catch(err=>{
        res.status(500).json({
            err:err
        })
    })
})

//修改专辑
album.put('/album/updateName',(req,res)=>{
    let {id,name}=req.query
    axios({
        url:'/Admin/Album/updateName',
        method:'put',
        params:{
            id:id,
            name:name
        },
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
    }).then(data=>{
        res.status(200).json({
            key:data.data
        })
    }).catch(err=>{
        res.status(500).json({
            err:err
        })
    })
})

//专辑搜索分页
album.get('/album/dimQuery',(req,res)=>{
    let {pageNow,name,pageSize}=req.query
    axios({
        url:'/Admin/Album/dimQuery',
        method:'get',
        params:{
            pageNow:pageNow||1,
            pageSize:pageSize||6,
            name:name
        },
        headers: {
            'Content-Type':'application/x-www-form-urlencoded',
            token:(req.session.token?req.session.token:'')
        },
    }).then(data=>{
        res.status(200).json({
            key:data.data
        })
    }).catch(err=>{
        res.status(500).json({
            err:err
        })
    })
})

module.exports=album